Support ssh remotes with '#' and '?' in the path to the repository
authorJoey Hess <joeyh@joeyh.name>
Mon, 20 Oct 2025 19:35:24 +0000 (15:35 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 20 Oct 2025 19:35:24 +0000 (15:35 -0400)
The same way git does.

Affected repository types are regular git ssh remotes, and also gcrypt
remotes, and potentially also bup remotes.

repoPath is used for such repositories accessed over ssh. uriPath is used
in some other places, eg the bittorrent special remote, where it would not
be appropriate to mimic git's behavior. The distinction seems to hold up
well from what I can see.

The ordering of uriFragment after uriQuery is to correctly handle cases
where both appear in an url. "ssh://localhost/tmp/foo?baz#bar" has an
uriFragment of "#bar" and an uriQuery of "?baz". On the other hand,
"ssh://localhost/tmp/foo#baz?bar" has an uriFragment of "#baz?bar" and no
uriQuery.

Sponsored-by: Dartmouth College's DANDI project
CHANGELOG
Git.hs
doc/bugs/fails_to_discover_uuid_over_ssh_with___35___in_path_.mdwn
doc/bugs/fails_to_discover_uuid_over_ssh_with___35___in_path_/comment_1_00c1062abe02a42cea491f6bb8e6e5dc._comment [new file with mode: 0644]

index c9eabe919c6147f0e33a9feebe3c6cf615cef850..21888c75f18ab964a88e19c4f76df327554d4415 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,10 @@
+git-annex (10.20250930) UNRELEASED; urgency=medium
+
+  * Support ssh remotes with '#' and '?' in the path to the repository,
+    the same way git does.
+
+ -- Joey Hess <id@joeyh.name>  Mon, 20 Oct 2025 15:22:30 -0400
+
 git-annex (10.20250929) upstream; urgency=medium
 
   * enableremote: Allow type= to be provided when it does not change the
diff --git a/Git.hs b/Git.hs
index 3eafcd674bc7019831747290205bcc0f8a8e37ac..30930c2c1799392cd8008f67674f61c8f2604696 100644 (file)
--- a/Git.hs
+++ b/Git.hs
@@ -38,7 +38,7 @@ module Git (
        relPath,
 ) where
 
-import Network.URI (uriPath, uriScheme, unEscapeString)
+import Network.URI (uriPath, uriScheme, uriQuery, uriFragment, unEscapeString)
 #ifndef mingw32_HOST_OS
 import System.Posix.Files
 #endif
@@ -73,7 +73,10 @@ repoLocation Repo { location = Unknown } = giveup "unknown repoLocation"
  - it's the gitdir, and for URL repositories, is the path on the remote
  - host. -}
 repoPath :: Repo -> OsPath
-repoPath Repo { location = Url u } = toOsPath $ unEscapeString $ uriPath u
+repoPath Repo { location = Url u } = toOsPath $ unEscapeString $
+       -- git allows the path of a ssh url to include both '?' and '#',
+       -- and treats them as part of the path
+       uriPath u ++ uriQuery u ++ uriFragment u
 repoPath Repo { location = Local { worktree = Just d } } = d
 repoPath Repo { location = Local { gitdir = d } } = d
 repoPath Repo { location = LocalUnknown dir } = dir
index bd5130b64f0db01511305a6a88208e8871373a5e..1b3ebda7ebed849df2243beba3b870ba886462d3 100644 (file)
@@ -72,3 +72,5 @@ FTR: I was trying to backup some old behavioral videos (octopus) from the laptop
 
 [[!meta author=yoh]]
 [[!tag projects/dandi]]
+
+> [[fixed|done]] --[[Joey]]
diff --git a/doc/bugs/fails_to_discover_uuid_over_ssh_with___35___in_path_/comment_1_00c1062abe02a42cea491f6bb8e6e5dc._comment b/doc/bugs/fails_to_discover_uuid_over_ssh_with___35___in_path_/comment_1_00c1062abe02a42cea491f6bb8e6e5dc._comment
new file mode 100644 (file)
index 0000000..f035f56
--- /dev/null
@@ -0,0 +1,11 @@
+[[!comment format=mdwn
+ username="joey"
+ subject="""comment 1"""
+ date="2025-10-20T19:16:15Z"
+ content="""
+Also affected is '?' in the path. It's somewhat surprising to me that git
+treats these parts of an url as path components, but
+not too surprising, as git's definition of "url" is pretty loose.
+
+Fixed git-annex to follow suite.
+"""]]